import { instance } from '@/http/index'
import { BatchDto, SearchDto, UpdateStatusDto } from '@/types/dto'
import { PaginatedResponse } from '@/types/interface'
import { ApiResponseVo } from '@/types/vo'

import { UserCriteria, UserModalDto } from './type/dto'
import { UserItem } from './type/vo'

/** ************** 增加( Create ) *******************/
export const createUser = (data: UserModalDto): Promise<ApiResponseVo> => instance.post('/users/create', data)

/** ************** 读取( Read ) *******************/
export const getUserList = (params: SearchDto<UserCriteria>): Promise<ApiResponseVo<PaginatedResponse<UserItem>>> =>
  instance.post('/users/list', params)

/** ************** 修改( Update ) *******************/
export const updateUser = (data: UserModalDto): Promise<ApiResponseVo> => instance.post('/users/update', data)

export const updateUserStatus = (data: UpdateStatusDto): Promise<ApiResponseVo> => instance.post('/users/status', data)

/** ************** 删除( Delete ) *******************/
export const deleteUser = (data: BatchDto): Promise<ApiResponseVo> => instance.post('/users/delete', data)
